package cn.zn.flow.service.impl;

import cn.zn.flow.entity.FlowRollback;
import cn.zn.flow.mapper.FlowRollbackMapper;
import cn.zn.flow.service.FlowRollbackService;
import cn.zn.flowTemplate.enums.FlowStatusEnum;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 回退记录 服务实现类
 * </p>
 *
 * @author zn-admin
 * @since 2021-07-13
 */
@Service
public class FlowRollbackServiceImpl extends ServiceImpl<FlowRollbackMapper, FlowRollback> implements FlowRollbackService {

    @Override
    @Transactional
    public void insertFlowRollback(String dataId, String table, String reason) {
        // 业务表回退
        baseMapper.tableRollback(table, dataId, FlowStatusEnum.ROLLBACK.getValue(), reason);
        // 回退记录
        FlowRollback rollback = new FlowRollback();
        rollback.setDataId(dataId);
        rollback.setMainTable(table);
        rollback.setReason(reason);
        baseMapper.insert(rollback);
    }
}
